package com.fr.zizouqi;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;

/**
 * @author 付荣
 * @version 创建时间：2019年1月31日 下午5:59:52
 */
public class Read {

	public static void main(String[] args) throws Exception {
		FileReader fr = new FileReader("E:\\aa.txt");
		BufferedReader br = new BufferedReader(fr);
		String line = br.readLine();
		Set<String> set = new HashSet<>();
		//英雄  - 属性
		Map<String, List<String>> map = new HashMap<>();
		//属性  - 英雄 
		Map<String, List<String>> map1 = new HashMap<>();
		List<String> list = null;
		String name = null;
		while(line != null){
			if (line.contains("★")){
				name = line.substring(0, line.length() - 1);
				list = new ArrayList<>();
				map.put(name, list);
			}else{
				list.add(line);
				set.add(line);
				List<String> l = map1.get(line);
				if (l == null){
					l = new ArrayList<>();
					map1.put(line, l);
				}
				l.add(name);
			}
			line = br.readLine();
		}
		br.close();
		fr.close();
		System.out.println(map);
		System.out.println(map1);
		System.out.println(set);
		Map<String, Integer> map2 = new TreeMap<>();
		for(Entry<String, List<String>> entry : map1.entrySet()){
			String type = entry.getKey();
			List<String> names = entry.getValue();
			for(String s : names){
				List<String> types = map.get(s);
				for(String ss : types){
					if(!type.equals(ss)){
						String key = type + "_" + ss;
						Integer count = map2.get(key);
						if (count == null){
							count = 0;
						}
						count ++;
						map2.put(key, count);
					}
				}
			}
		}
		for(Entry<String, List<String>> entry : map1.entrySet()){
			String type = entry.getKey();
			List<String> names = entry.getValue();
			System.out.println(type + ":");
			for(String s : names){
				System.out.print(s + ":");
				List<String> types = map.get(s);
				for(String ss : types){
					if(!type.equals(ss)){
						System.out.print(ss + ",");
					}
				}
				System.out.println();
			}
			System.out.println();
		}
		for(Entry<String, Integer>entry : map2.entrySet()){
			if(entry.getValue() > 1){
				System.out.println(entry);
			}
		}
		System.out.println(map2);
	}
}
